package draw.impl;

import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;

/**
 * StaticStroke is a collection of Points, a digital
 * representation of an actual brush stroke.
 *
 * @author Matthew B. Gray <matthew.b.gray@gmail.com>
 * @version 1.0
 */
public class StaticStroke implements Comparable, Iterable {
	private static Integer lastElement=0; // Global element tracker.
	private Integer element; // Element number.
	private List<Point> points; //An ordered set of points.
	private boolean used=false; //indicates if element has been used in an animated stroke.

	public StaticStroke(StaticStroke that) {
		this();
		this.points.addAll(that.points);
	}
	public StaticStroke() {
		points = new LinkedList<Point>();
		element = lastElement++;
	}
	protected void resetOrder() { lastElement = 0; }
	protected void add(Point p) { points.add(p); }
	protected int size() { return points.size(); }

	public Iterator<Point> iterator() { return points.iterator(); }
	public boolean isUsed() { return used; }
	public void setUsed() { used = true; }

	public Object clone() {
		StaticStroke toReturn = new StaticStroke();
		lastElement--; // put lastElement back to where it was.
		toReturn.element = this.element;
		toReturn.points.addAll(this.points);
		return toReturn;
	}

	public String toString() {
		StringBuffer buff = new StringBuffer("Static Stroke: ");
		for(Point p : points)
			buff.append(p.toString()).append(", ");
		return buff.toString();
	}

	/**
	 * Sorted by order of creation.
	 * @see this{@link #element}
	 */
	public int compareTo(Object that) {
		return this.element.compareTo(((StaticStroke)that).element);
	}
}
